<template>
	<view class="newsHead">
		<u-navbar :is-back="true" :border-bottom="false" back-icon-color="#444444">
			<view class="slot-wrap">
				<view class="nav_center single-omit">
					<text>新闻资讯</text>
				</view>
			</view>
			<view class="navbar-right" slot="right">
				<!-- 	<u-icon name="share" size="30" color="#333333"></u-icon> -->
				<text class="iconfont iconfenxiang1"></text>
			</view>
		</u-navbar>
		<view class="content">
			<view class="tit">
				{{item.newsName || "暂无"}}
			</view>
			<view class="msg">
				<view class="con">
					<!-- 	<u-image width="66" height="66" class="img" src="http://www.people.com.cn/img/2016people/images/rmw_logo.png"
					 shape="circle">

					</u-image> -->
					<view class="inform">
						<view class="topCon">
							<text class="txt">{{ item.source|| "暂无"}}</text>
							<view class="tag" v-if="item.columnList && item.columnList.length>0">
								{{item.columnList[0].columnName}}
							</view>
						<!-- 	<view class="tag more" v-if="item.columnList && item.columnList.length>1">
								...
							</view> -->
						</view>

						<view class="matter">
							<view class="leftCon">
								<view class="time">
									{{handleDate(item.showDate || '', 'yyyy-MM-dd')}}
								</view>

								<!-- 	  <view class="tag more">
									
								</view> -->
								<text class="iconfont iconchakanliang"></text>
								<text class="see_count">{{handleCount(item.lookNum || 0,10000)}}</text>
							</view>

						
						</view>
					</view>
					<view class="rightCon">
						<check-user-status @click="handleZan">
							<view class="item">
								<text v-if="!item.isGood" class="iconfont icondianzan2"></text>
								<text v-else class="iconfont iconyidianzan"></text>
								<text class="count" :class="{isZan:item.isGood == 1}">{{handleCount(item.goodNum || 0,10000)}}</text>
							</view>
						</check-user-status>
						<check-user-status @click="handleCollect" style="margin-left: 20rpx;">
							<view class="item">
								<text v-if="!item.isCollect" class="iconfont iconshoucang"></text>
								<text v-else class="iconfont iconyishoucang"></text>
								<!-- <text  class="count">3021</text> -->
							</view>
						</check-user-status>
					</view>
				</view>

			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import CheckUserStatus from "@/components/CheckUserStatus.vue"
	import {
		handleDate,
		handleCount
	} from '@/utils/util.js'
	export default {
		props: {
			item: {
				type: Object,
				default: () => {}
			},
		},
		components: {
			CheckUserStatus
		},
		data() {
			return {
				isLike: true,
				isZan: true
			};
		},
		methods: {
			handleDate,
			handleCount,
			async handleZan() {
				if (!this.item.isGood) {
					await this.doZan();
					return;
				}
				await this.cancleZan();
			},
			async handleCollect() {
				if (!this.item.isCollect) {
					await this.doCollect();
					return;
				}
				await this.cancelCollect();
			},
			/**
			 * 点赞
			 */
			async doZan() {

				const result = await this.$api.addNewsGood({
					newsCode: this.item.newsCode,
					newsName: this.item.newsName,
					userCode: this.store_user_code
				});

				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '点赞成功',
						type: 'success',
						duration: 2000
					});
					this.item.goodNum = this.item.goodNum + 1;
					this.item.isGood = 1;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "点赞失败",
					type: 'error',
					duration: 2000
				});
			},
			/**
			 * 取消点赞
			 */
			async cancleZan() {
				const result = await this.$api.deleteNewsGood({
					newsCode: this.item.newsCode,
					userCode: this.store_user_code
				});
				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '已取消点赞',
						type: 'success',
						duration: 2000
					});
					this.item.goodNum = this.item.goodNum - 1;
					this.item.isGood = 0;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "取消失败",
					type: 'error',
					duration: 2000
				});
			},

			/**
			 * 收藏
			 */
			async doCollect() {
				const result = await this.$api.addNewsCollection({
					newsCode: this.item.newsCode,
					newsName: this.item.newsName,
					userCode: this.store_user_code
				});

				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '收藏成功',
						type: 'success',
						duration: 2000
					});
					this.item.isCollect = 1;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "收藏失败",
					type: 'error',
					duration: 2000
				});
			},
			/**
			 * 取消收藏
			 */
			async cancelCollect() {
				const result = await this.$api.deleteNewsCollection({
					newsCode: this.item.newsCode,
					userCode: this.store_user_code
				});
				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '已取消收藏',
						type: 'success',
						duration: 2000
					});
					this.item.isCollect = 0;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "取消收藏失败",
					type: 'error',
					duration: 2000
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "../../../../../commom/styles/icons.css";

	.newsHead {
		/deep/.u-slot-content {
			display: flex;
			justify-content: center;

			.slot-wrap {
				max-width: 600rpx;
				font-size: 32rpx;
				font-weight: 400;
				line-height: 88rpx;
				color: #333333;
			}
		}

		.navbar-right {
			font-size: 30rpx;
			margin-right: 24rpx;
			color: #333333;
		}

		.content {
			padding: 20rpx;

			.tit {
				font-size: 40rpx;
				font-weight: 600;
				color: #333333;

			}

			.msg {
				width: 100%;
				padding-top: 26rpx;
				padding-bottom: 8rpx;
				display: flex;

				.con {
					flex: 1;
					display: flex;
                    height: 78rpx;
					align-items: center;
					.img {
						border: 1px solid #D8D8D8;
					}

					.inform {
						// height: 66rpx;
						display: flex;
						// flex: 1;
						flex-direction: column;
						// margin-left: 20rpx;
						justify-content: space-between;
                        // background: blue;
						// margin-top: -10rpx;
						.topCon {
							width: 100%;
							display: flex;
                            align-items: center;
							height: 42rpx;
							// background: red;
							.txt {
								font-size: 30rpx;
								font-weight: 400;
								color: #555555;
								margin-right: 30rpx;
								margin-top: -4rpx;
								max-width: 400rpx;
								@include line-ellipsis(1);
								// background: red;
							}

							.tag {
								height: 34rpx;
								padding: 0 16rpx;
								background: #FF7D77;
								border-radius: 5rpx;
								color: #FFFFFF;
								font-size: 20rpx;
								display: flex;
								align-items: center;

								&.more {
									margin-left: 10rpx;
								}
							}
						}


						.matter {
							font-size: 22rpx;
							font-weight: 400;
							color: #9E9E9E;
							display: flex;
							align-items: flex-end;
							justify-content: space-between;
							margin-top: 10rpx;

							.leftCon {
								display: flex;
								align-items: center;
                                
								.time {
									// margin-right: 20rpx;
									font-size: 22rpx;
								}


								.iconchakanliang {
									font-size: 24rpx;
									margin-left: 24rpx;
									margin-right: 11rpx;
									// margin-top: 10rpx;
									color: #9E9E9E;
								}
							}



							.see_count {
								font-size: 24rpx;
								font-weight: 400;
								color: #9E9E9E;
							}

						
						}
					}
					.rightCon {
						display: flex;
						flex: 1;
						justify-content: flex-end;
					    // background: red; 
					
						.item {
							display: flex;
							color: #9E9E9E;
							font-size: 24rpx;
					
							
					
							.count {
								font-size: 22rpx;
								font-weight: 500;
								color: #999999;
								margin-top: -15rpx;
								margin-left: -5rpx;
					
								&.isZan {
									color: #666666;
								}
							}
					
							.iconfont {
								font-size: 35rpx;
								// margin-bottom: 6rpx;
					
								&.iconyidianzan {
									display: flex;
									background-image: linear-gradient(90deg, #FE614F 0%, #EB4D3C 100%);
									-webkit-background-clip: text;
									color: transparent;
								}
					
								&.iconyishoucang {
									display: flex;
									background-image: linear-gradient(150deg, #FFED6F 1%, #FFCF01 100%);
									-webkit-background-clip: text;
									color: transparent;
								}
								
							}
						}
					}
				}

			}
		}
	}
</style>
